home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / _WRITE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  755 b   |  29 lines

  1. /* _WRITE.C --- p. 677 */
  2. #include <stdio.h>
  3. #include <fcntl.h>
  4. #include <io.h>
  5. char buffer[80] = "Testing _write ...........";
  6. main()
  7. {
  8.     char fname[40], *p_fname;
  9.     int filehandle, bytes;
  10.     printf("Enter name of an existing file: ");
  11.     p_fname = gets(fname);
  12.                     /* Open the file using _open  */
  13.     if((filehandle = _open(p_fname, O_RDWR)) == -1)
  14.     {
  15.         printf("Error opening file: %s\n", fname);
  16.         exit(0);
  17.     }
  18.     printf("File %s opened.\n", fname);
  19.                     /* Now write out buffer */
  20.     if((bytes = _write(filehandle, buffer, 80)) != -1)
  21.         printf("%d bytes written\n", bytes);
  22.                     /* Now close the file */
  23.     if(_close(filehandle) != 0)
  24.     {
  25.         printf("Error closing file with _close\n");
  26.         exit(0);
  27.     }
  28.     printf("File %s closed.\n", fname);
  29. }